package Leetcode.lc012;

import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;

/***
 * 有用的括号
 */
public class Sloution {
    public boolean isValid(String s) {
        //存储条件可能
        HashMap<Character, Character> map = new HashMap<>();
        map.put(')','(');
        map.put(']','[');
        map.put('}','{');
        Deque<Character> stack=new LinkedList<>();
        for(int i=0;i<s.length();i++){
            if(map.containsKey(s.charAt(i))){
                if(map.get(s.charAt(i))!=stack.peek()){
                    return false;
                }
                stack.pop();
            }else {
                stack.push(s.charAt(i));
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        Sloution sloution = new Sloution();
        String s = "([])";
        if(!sloution.isValid(s)){
            System.out.print("非法");
        }else{
            System.out.print("你好");
        }
    }
}
